package com.jiepos.mpos.biz.channel.service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.jiepos.mpos.common.constant.DBConstant.Table;
import com.jiepos.mpos.common.dao.InfChnCustomServiceDao;
import com.jiepos.mpos.common.entity.App_Inf_Chn_Custom_ServiceEntity;
import com.jiepos.mpos.core.entity.Pagination;
import com.jiepos.mpos.core.service.BaseService;
import com.jiepos.mpos.core.util.StringUtils;

/**
 * 
 * 
 * <p>
 * 标题: —— 会员渠道业务参数扣率业务类
 * </p>
 * <p>
 * 模块: 通用平台
 * </p>
 * <p>
 * 版权: Copyright (c) 2017 江苏杰博实信息技术有限公司
 * 
 * @ProjectName: [mpos]
 * @Package com.jiepos.mpos.biz.channel.service
 * @author 张学涛
 * @version 1.0
 * @since 2017年9月26日下午2:21:01 @history（历次修订内容、修订人、修订时间等）
 */
@Service
public class InfChnCustomServiceService extends BaseService {

	@Autowired
	private InfChnCustomServiceDao infChnCustomServiceDao;

	/**
	 * 
	 * @param pagination
	 * @param app_Inf_Chn_Custom_ServiceEntity
	 * @return
	 */
	@SuppressWarnings({ "unchecked", "rawtypes" })
	public Map getInfChnCustomService(Pagination pagination,
			App_Inf_Chn_Custom_ServiceEntity app_Inf_Chn_Custom_ServiceEntity, String custom_name,
			String custom_login_id) {
		StringBuffer sb = getInitSql("t1").append(",");
		List list = new ArrayList();
		sb.append("t1.channel_custom_service_uuid, ").append("t1.custom_no, ")
				.append("CONCAT(RPAD(SUBSTR(t2.LOGIN_ID, 1, 3),LENGTH (t2.LOGIN_ID) - 4,'*'),SUBSTR (t2.LOGIN_ID,LENGTH (t2.LOGIN_ID) - 3,4))||'-'||t2.name as custom_nm, ")
				.append("t3.service_no||'-'||t3.service_name as service_nm, ")
				.append("t4.param_no||'-'||t4.param_name as param_nm, ")
				.append("NVL2(t5.channel_no||t5.chn_nm, t5.channel_no||'-'||t5.chn_nm, '') as channel_nm, ")
				.append("NVL2(t1.CREDIT_MIN_RATE, to_char(t1.CREDIT_MIN_RATE/100,'fm99999999999990.00')||'%', '') as CREDIT_MIN_RATE, ")
				.append("to_char(t1.CREDIT_MIN_ATTACHFEE,'fm99999999999990.00') as CREDIT_MIN_ATTACHFEE, ")
				.append("to_char(t1.CREDIT_MIN_FEE,'fm99999999999990.00') as CREDIT_MIN_FEE, ")
				.append("to_char(t1.CREDIT_MIN_MAXFEE,'fm99999999999990.00') as CREDIT_MIN_MAXFEE ").append(" from ")
				.append(Table.T_APP_INF_CHN_CUSTOM_SERVICE).append(" t1 ").append(" left join  ")
				.append(Table.T_APP_CUSTOM_INF).append(" t2 ").append(" on t1.custom_no = t2.custom_no ")
				.append(" left join ").append(Table.T_APP_SERVICE_INF).append(" t3 ")
				.append(" on t1.service_no = t3.service_no ").append(" left join ").append(Table.T_APP_SERVICE_PARAM)
				.append(" t4 ").append(" on t1.param_no = t4.param_no ").append(" left join ")
				.append(Table.T_APP_INF_CHANNEL).append(" t5 on t1.channel_no = t5.channel_no ").append(" where 1=1 ");
		if (!StringUtils.isBlank(app_Inf_Chn_Custom_ServiceEntity.getCustom_no())) {
			sb.append(" and t2.custom_no LIKE ? ");
			list.add("%" + app_Inf_Chn_Custom_ServiceEntity.getCustom_no() + "%");
		}
		if (!StringUtils.isBlank(custom_name)) {
			sb.append(" and t2.name Like ? ");
			list.add("%" + custom_name + "%");
		}
		if (!StringUtils.isBlank(custom_login_id)) {
			sb.append(" and t2.login_id like ? ");
			list.add("%" + custom_login_id + "%");
		}
		if (!StringUtils.isBlank(app_Inf_Chn_Custom_ServiceEntity.getService_no())) {
			sb.append(" and t3.service_uuid = ? ");
			list.add(app_Inf_Chn_Custom_ServiceEntity.getService_no());
		}
		if (!StringUtils.isBlank(app_Inf_Chn_Custom_ServiceEntity.getParam_no())) {
			sb.append(" and t4.service_param_uuid = ? ");
			list.add(app_Inf_Chn_Custom_ServiceEntity.getParam_no());
		}
		if (!StringUtils.isBlank(app_Inf_Chn_Custom_ServiceEntity.getChannel_No())) {
			sb.append(" and t5.channel_no = ? ");
			list.add(app_Inf_Chn_Custom_ServiceEntity.getChannel_No());
		}
		pagination.queryString = sb.toString();
		pagination = this.getOrderSql(pagination, "t1");
		return infChnCustomServiceDao.getPaginationMap(pagination, "t1", list);
	}

}
